﻿using System;
using System.Collections.Generic;
using HAVNet.Core.String;
using HAVNet.Core.Lambda;


namespace HAVNet.Intros.AST
{
    public class ASTUsings : List<ASTUsing>
    {
        public override string ToString()
        {
            return Strings.joinobjs (Environment.NewLine, this);
        }

        public string ToString2 (int depth)
        {
            string s = "";

            foreach (ASTUsing u in this)
            {
                s += Strings.tab(depth) + u.ToString().Trim();
                s += Environment.NewLine;
            }

            return s;
        }
    }

    public class ASTUsing : ASTNode
    {
        public readonly string      name        = null;
        public readonly string      usingAlias  = null;
        public readonly ASTTypeName typeName    = null;

        public ASTUsing (string name, ASTTypeName typeName, string usingAlias)
        {
            this.name       = name;
            this.usingAlias = usingAlias;
            this.typeName   = typeName;
        }

        public ASTUsing (string name, ASTTypeName typeName)
            : this (name, typeName, null)
        { }

        public override string ToString ()
        {
            depth++;

            string ret =
            ((usingAlias != null) && (usingAlias != "")) ?
                "using " + usingAlias + " = " + typeName.ToString() + ";"
                :
                "using " + typeName.ToString() + ";";

            ret = Strings.tab(depth) + ret;

            depth--;

            return ret;
        }
    }
}
